package loggeri.android.namespace;

import java.util.ArrayList;
import java.util.Calendar;

import android.app.Activity;
import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.Toast;

public class CheckBoxHandler implements OnClickListener{
	
	
	
	//private Chain chain;
	
	public CheckBoxHandler(){}
	
	
	public CheckBox makeCheckBox(Activity ac, Chain chain){
	
		CheckBox cb = new CheckBox(ac);
		
			cb.setButtonDrawable(R.drawable.custom_checkbox);
		
		
		int id = this.luoID(chain);
		chain.getLastNode().setId(id);
		cb.setId(id);
		
		final String idStr = cb.getId()+"";
		
		
		
		cb.setOnClickListener(this);
		
		
		
		
		
		
		
		
		return cb;
		
	}
	
	
	public Integer luoID(Chain ch){
		Integer id;
		
		Calendar nyt = Calendar.getInstance();
		Integer paiva = nyt.get(Calendar.DAY_OF_MONTH);
		Integer kk = nyt.get(Calendar.MONTH) + 1;
		Integer vuosi = nyt.get(Calendar.YEAR);
		String chainid = "" + ch.getId();
		
		if(ch.getId() < 10) {
			chainid = "0" + ch.getId();
		}
		
		
		String kokoid = vuosi.toString() + "" + kk.toString() + "" + paiva.toString() + "" + chainid;
		id = Integer.parseInt(kokoid);
		
		
		
		return id;
	}


	@Override
	public void onClick(View v) {
		if (((CheckBox) v).isChecked()) {
			Log.d("CHECKBOX",v.getId()+"");
			
			//v.setBackgroundResource(R.drawable.custom_checkbox_clicked);
			
			((CheckBox) v).setButtonDrawable(R.drawable.custom_checkbox_clicked);
			
		}
		else {
			((CheckBox) v).setButtonDrawable(R.drawable.custom_checkbox);
		}
	}
	

}
